// DlgRecord.cpp : implementation file
//

#include "stdafx.h"
#include "bdc.h"
#include "DlgRecord.h"
#include "afxdialogex.h"

using namespace bdc::dlg;


// DlgRecord dialog

IMPLEMENT_DYNAMIC(DlgRecord, CDialogEx)

DlgRecord::DlgRecord(CWnd* pParent /*=NULL*/)
	: CDialogEx(DlgRecord::IDD, pParent)
{

}

DlgRecord::~DlgRecord()
{
}

void DlgRecord::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_RECORD_MEMORY, memory);
	DDX_Text(pDX, IDC_RECORD_DES, description);
	DDX_Text(pDX, IDC_RECORD_TAG, tag);
}


BEGIN_MESSAGE_MAP(DlgRecord, CDialogEx)
END_MESSAGE_MAP()


// DlgRecord message handlers


BOOL bdc::dlg::DlgRecord::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  Add extra initialization here
	this->UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


void bdc::dlg::DlgRecord::OnOK()
{
	// TODO: Add your specialized code here and/or call the base class

	CDialogEx::OnOK();

	CbdcApp* app = (CbdcApp*) AfxGetApp();

	BOOL success = FALSE;
	BOOL isAddRecord = recordId == 0;
	if(isAddRecord) {
		success = app->serviceInvoker.addRecord(memory.GetString(), description.GetString(), tag.GetString());
	}
	else {
		success = app->serviceInvoker.updateRecord(recordId, memory.GetString(), description.GetString(), tag.GetString());
	}
	
	if(!success) {
		MessageBox(_T("false"));
	}
}
